#ifndef maincontrol_H
#define maincontrol_H

#include <QObject>
#include <QAction>

#include "journalwindow.h"
#include "journaltabwidget.h"

class Document;

/**
 * Receives signals from the MainWindow and reacts to them.
 */
class MainControl : public QObject {
    Q_OBJECT

public:
    /**
     * Creates a new MainControl for the given window.
     * @param p_window The JournalWindow that is controlled by this object.
     **/
    MainControl(JournalWindow *p_window);

    /**
     * Return a referenc to the current document.
     */
    Document* currentDoc() { return (Document*)m_window->getTabWidget()->currentWidget(); }

private:
    /**
     * The reference on the parent window.
     */
    JournalWindow* m_window;

public slots:
    /**
     * Create a new document.
     */
    void newDocument();

    /**
     * Show the OpenFile-Dialog and try to open the user chosen file.
     */
    void openFile();

    /**
     * Save the open document to it's location.
     *
     * When no location is specified already, show the SaveFileAs-Dialog.
     */
    void saveFile();

    /**
     * Open the SaveFileDialog to let the user choose the path to save the
     * current document to.
     */
    void saveFileAs();

    /**
     * Save the current document to this location.
     * 
     * @param outputFileName The path to write the file to.
     */
    void saveFileAs(const QString &outputFileName);

    /**
     * Try to close a Document's tab.
     *
     * Ask the user to save when necessary.
     *
     * @param tab The index of the tab within the JournalTabWidget.
     */
    void closeDocument(int tab);

    /**
     * Starts the application when the window is shown.
     */
    void onWindowLoaded();

    /**
     * Receives the signal that the undo action has triggered and forwards it to the current document.
     */
    void undo();

    /**
     * Receives the signal that the redo action has triggered and forwards it to the current document.
     */
    void redo();

    /**
     * An action of the tool action group has been triggered to change the current tool.
     */
    void toolChanged(QAction *action);

    /**
     * An action of the pen size action group has been triggered to change the size of the current pen.
     */
    void penSizeChanged(QAction *action);

    /**
     * Handles the signal, that a document has changed its name.
     */
    void documentNameChanged(QString newName, Document *source);

    /**
     * Zoom the current document to fit the width of the current page.
     */
    void zoomWidth();

    /**
     * Reset the zoom level to the original factor.
     */
    void zoomOrig();

    /**
     * Increase the zoom level.
     */
    void zoomIn();

    /**
     * Decrease the zoom level.
     */
    void zoomOut();

    /**
     * Zoom to fit the whole page into the view.
     */
    void zoomFit();

};

#endif
